local zhiba = fk.CreateSkill {

  name = "joyex__zhiba$",

  tags = {  },

}



zhiba:addEffect(fk.EventAcquireSkill, {
  refresh_events = {fk.EventAcquireSkill, fk.EventLoseSkill, fk.BuryVictim, fk.AfterPropertyChange},
  can_refresh = function(self, event, target, player, data)
    if event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
      return data == self
    elseif event == fk.BuryVictim then
      return target:hasSkill(self, true, true)
    elseif event == fk.AfterPropertyChange then
      return target == player
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local attached_huangtian = player.kingdom == "wu" and table.find(room.alive_players, function (p)
      return p ~= player and p:hasSkill(self, true)
    end)
    if attached_huangtian and not player:hasSkill("joyex__zhiba_other&", true, true) then
      room:handleAddLoseSkills(player, "joyex__zhiba_other&", nil, false, true)
    elseif not attached_huangtian and player:hasSkill("joyex__zhiba_other&", true, true) then
      room:handleAddLoseSkills(player, "-joyex__zhiba_other&", nil, false, true)
    end
  end,
})
zhiba:addEffect(fk.EventLoseSkill, {
  refresh_events = {fk.EventAcquireSkill, fk.EventLoseSkill, fk.BuryVictim, fk.AfterPropertyChange},
  can_refresh = function(self, event, target, player, data)
    if event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
      return data == self
    elseif event == fk.BuryVictim then
      return target:hasSkill(self, true, true)
    elseif event == fk.AfterPropertyChange then
      return target == player
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local attached_huangtian = player.kingdom == "wu" and table.find(room.alive_players, function (p)
      return p ~= player and p:hasSkill(self, true)
    end)
    if attached_huangtian and not player:hasSkill("joyex__zhiba_other&", true, true) then
      room:handleAddLoseSkills(player, "joyex__zhiba_other&", nil, false, true)
    elseif not attached_huangtian and player:hasSkill("joyex__zhiba_other&", true, true) then
      room:handleAddLoseSkills(player, "-joyex__zhiba_other&", nil, false, true)
    end
  end,
})
zhiba:addEffect(fk.BuryVictim, {
  refresh_events = {fk.EventAcquireSkill, fk.EventLoseSkill, fk.BuryVictim, fk.AfterPropertyChange},
  can_refresh = function(self, event, target, player, data)
    if event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
      return data == self
    elseif event == fk.BuryVictim then
      return target:hasSkill(self, true, true)
    elseif event == fk.AfterPropertyChange then
      return target == player
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local attached_huangtian = player.kingdom == "wu" and table.find(room.alive_players, function (p)
      return p ~= player and p:hasSkill(self, true)
    end)
    if attached_huangtian and not player:hasSkill("joyex__zhiba_other&", true, true) then
      room:handleAddLoseSkills(player, "joyex__zhiba_other&", nil, false, true)
    elseif not attached_huangtian and player:hasSkill("joyex__zhiba_other&", true, true) then
      room:handleAddLoseSkills(player, "-joyex__zhiba_other&", nil, false, true)
    end
  end,
})
zhiba:addEffect(fk.AfterPropertyChange, {
  refresh_events = {fk.EventAcquireSkill, fk.EventLoseSkill, fk.BuryVictim, fk.AfterPropertyChange},
  can_refresh = function(self, event, target, player, data)
    if event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
      return data == self
    elseif event == fk.BuryVictim then
      return target:hasSkill(self, true, true)
    elseif event == fk.AfterPropertyChange then
      return target == player
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local attached_huangtian = player.kingdom == "wu" and table.find(room.alive_players, function (p)
      return p ~= player and p:hasSkill(self, true)
    end)
    if attached_huangtian and not player:hasSkill("joyex__zhiba_other&", true, true) then
      room:handleAddLoseSkills(player, "joyex__zhiba_other&", nil, false, true)
    elseif not attached_huangtian and player:hasSkill("joyex__zhiba_other&", true, true) then
      room:handleAddLoseSkills(player, "-joyex__zhiba_other&", nil, false, true)
    end
  end,
})

return zhiba